var t = require("../../../@babel/runtime/helpers/defineProperty"), o = getApp();

Page({
    externalClasses: [ "tabs" ],
    data: {
        mainInfo: {},
        page_id: "",
        clientWidth: "375",
        btnFlag: !1,
        store_components: [],
        store_pageInfo: {},
        bottom_info: {},
        foot_type: "",
        bottomShowBol: !1,
        bottomShowBolIndex: 0,
        store_id: "",
        albumList: [],
        tabList: [],
        storeInfo: "",
        coupons: [],
        swiperIndex: 0,
        showMoreAlbum: !1,
        active: "store_info",
        showServicePopup: !1,
        contactPerson: {},
        U_tabcontrol: !0,
        isLoadMore: !0,
        goodsData: {
            preview_color: "#f5f5f5",
            sort_style: {
                choose_icon: "2"
            },
            padding_top: 0,
            padding_bottom: 0,
            padding_left: 10,
            padding_right: 10,
            item_radius: 5,
            show_shadow: !1,
            show_border: !1,
            border_color: "#BFB7B7",
            good_tag: {
                choose_icon: "0",
                image: ""
            },
            button_type: "3",
            button_title: "立即购买",
            button_bg_color: "#ff2c29",
            button_color: "#ffffff",
            content_list: [ "1", "3", "4", "7" ],
            show_price_text: !1,
            disable_good: "0",
            goods_type: "list"
        },
        navigationBarTitle: ""
    },
    onLoad: function(t) {
        if (t.scene) {
            var a = this.sceneDecode(t.scene).store_id;
            o.globalData.STORE_ID = a, o.globalData.store_alone_temp = 1, this.setData({
                store_id: a
            });
        }
        (t.store_id || t.store_alone_id) && (o.globalData.STORE_ID = t.store_id || t.store_alone_id, 
        o.globalData.store_alone_temp = 1, this.setData({
            store_id: t.store_id || t.store_alone_id
        })), this.data.store_id ? this.getData() : wx.redirectTo({
            url: "/packageG/independent_store/access_tip/access_tip"
        });
    },
    onShow: function() {},
    onReachBottom: function() {
        this.setData({
            bottomShowBol: !0
        }), this.data.decorate_isLoadMore && this.getMorePluginData();
    },
    onShareAppMessage: function() {
        return {
            title: this.data.navigationBarTitle
        };
    },
    onPageScroll: function(t) {
        this.data.store_components && this.data.store_components.length > 0 && (t.scrollTop > 80 ? this.data.btnFlag || this.setData({
            btnFlag: !0
        }) : this.data.btnFlag && this.setData({
            btnFlag: !1
        }), this.data.bottomShowBol && this.setData({
            bottomShowBol: !1
        }));
    },
    sceneDecode: function(t) {
        var o = (t = decodeURIComponent(t)).split(","), a = {};
        return o.forEach(function(t, o) {
            var e = t.split("=")[0], n = t.split("=")[1];
            a[e] = n;
        }), a;
    },
    getData: function() {
        var a = this;
        wx.showLoading({
            title: "加载中"
        });
        var e = o.getNetAddresss("plugin.store-alone-temp.frontend.home.home-page");
        o._getNetWork({
            url: e,
            data: {
                store_id: this.data.store_id
            },
            success: function(e) {
                if (wx.hideLoading(), 1 !== e.data.result) return o.tips(e.data.msg), void wx.redirectTo({
                    url: "/packageG/independent_store/access_tip/access_tip"
                });
                var n = e.data;
                if (n.data.store_decorate && n.data.store_decorate.datas) return a.setData({
                    mainInfo: n.data.store_info,
                    page_id: n.data.store_decorate.id,
                    store_components: n.data.store_decorate.datas,
                    store_pageInfo: n.data.store_decorate.page_info,
                    foot_type: n.data.store_decorate.foot_type
                }), -1 == n.data.store_decorate.foot_type ? a.setData({
                    bottom_info: {}
                }) : 1 == n.data.store_decorate.foot_type ? n.data.store_decorate.foot_id && n.data.store_decorate.foot_id.page_info ? a.setData({
                    bottom_info: JSON.parse(n.data.store_decorate.foot_id.page_info)
                }) : a.setData({
                    bottom_info: {}
                }) : 2 == n.data.store_decorate.foot_type && (!n.data.store_decorate.foot_id || n.data.store_decorate.foot_id instanceof Array ? a.setData({
                    bottom_info: {}
                }) : a.setData({
                    bottom_info: JSON.parse(n.data.store_decorate.foot_id.page_info)
                })), a.data.navigationBarTitle = a.data.store_pageInfo.page_title || e.data.data.store_info.store_name || "商家", 
                wx.setNavigationBarTitle({
                    title: a.data.navigationBarTitle
                }), void wx.setNavigationBarColor({
                    backgroundColor: a.data.store_pageInfo.preview_color,
                    frontColor: 1 == a.data.store_pageInfo.font_color ? "#ffffff" : "#000000",
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                });
                var s = e.data.data;
                s.nav.nav.unshift({
                    code: "store_info",
                    name: "商家信息"
                }), s.photo && 6 == s.photo.length && s.photo.push({}), a.setData({
                    custom_name_state: s.custom_name_state,
                    albumList: s.photo || [],
                    storeInfo: s.store_info,
                    tabList: s.nav.nav,
                    coupons: s.store_info.coupon
                }), console.log(a.data.custom_name_state, "ddddd"), a.data.tabList.length > 1 && "recommend_goods" === a.data.tabList[1].code && a.setData(t({}, "goodsData.list", s.nav.data)), 
                a.data.navigationBarTitle = a.data.storeInfo.store_name, wx.setNavigationBarTitle({
                    title: a.data.navigationBarTitle
                });
            },
            fail: function(t) {
                wx.hideLoading();
            }
        });
    },
    changeTab: function(t) {
        this.setData({
            active: t.detail.name
        }), this.data.isLoadMore = !0;
    },
    getPlugins: function(a, e, n) {
        var s = this, i = o.getNetAddresss(a);
        o._getNetWork({
            url: i,
            data: e,
            success: function(o) {
                var a = o.data;
                1 == a.result && "recommend_goods" === n && s.setData(t({}, "goodsData.list", a.data.data));
            }
        });
    },
    getMorePluginData: function() {
        (this.data.isLoadMore = !1, "recommend_goods" === this.data.active) && this.selectComponent("#recommend_goods").loadMoreMemberData();
    },
    setLoadMore: function(t) {
        this.setData({
            isLoadMore: t.detail.isLoadMore
        });
    },
    goToAdress: function() {
        var t = this.data.storeInfo.latitude, a = this.data.storeInfo.longitude, e = this.data.storeInfo.store_name, n = o.BMapTransqqMap(parseFloat(a), parseFloat(t));
        wx.openLocation({
            latitude: n.lat,
            longitude: n.lng,
            scale: 18,
            name: e
        });
    },
    swiperChange: function(t) {
        this.setData({
            swiperIndex: t.detail.current
        }), this.data.albumList[0].label_data_count > 6 && 5 === t.detail.current ? this.setData({
            showMoreAlbum: !0
        }) : this.data.albumList[0].label_data_count > 6 && 6 === t.detail.current ? (this.setData({
            swiperIndex: 5
        }), this.goStoreAlbums()) : this.setData({
            showMoreAlbum: !1
        });
    },
    collectCoupons: function(t) {
        var a = t.currentTarget.dataset.item;
        if (3 != a.api_availability) {
            var e = o.getNetAddresss("coupon.member-coupon.get-coupon");
            wx.showLoading({
                title: "loading"
            }), o._postNetWork({
                url: e,
                data: {
                    coupon_id: a.id
                },
                success: function(t) {
                    wx.hideLoading();
                    var o = t.data;
                    1 == o.result ? wx.showToast({
                        title: "领取成功",
                        icon: "none",
                        duration: 2e3
                    }) : wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 2e3
                    });
                },
                fail: function() {
                    wx.hideLoading();
                }
            });
        }
    },
    showServicePopup: function() {
        this.setData({
            showServicePopup: !0
        });
    },
    closeServicePopup: function() {
        this.setData({
            showServicePopup: !1
        });
    },
    showContactPopup: function(t) {
        this.setData({
            "contactPerson.mobile": t.currentTarget.dataset.mobile,
            "contactPerson.name": t.currentTarget.dataset.name,
            showContactPopup: !0
        });
    },
    contactStaff: function(t) {
        this.setData({
            "contactPerson.mobile": t.detail.mobile,
            "contactPerson.name": t.detail.name,
            showContactPopup: !0
        });
    },
    callPhone: function() {
        wx.makePhoneCall({
            phoneNumber: this.data.contactPerson.mobile
        });
    },
    copyPhone: function() {
        wx.setClipboardData({
            data: this.data.contactPerson.mobile,
            success: function(t) {},
            fail: function(t) {
                wx.showToast({
                    title: "复制失败",
                    icon: "none"
                });
            }
        });
    },
    addPhone: function() {
        wx.addPhoneContact({
            firstName: this.data.contactPerson.name,
            mobilePhoneNumber: this.data.contactPerson.mobile
        });
    },
    closeContactPopup: function(t) {
        this.setData({
            showContactPopup: !1
        });
    },
    phoneCall: function(t) {
        var o = t.currentTarget.dataset.mobile;
        o && wx.makePhoneCall({
            phoneNumber: o
        });
    },
    gotoChat: function(t) {
        var a = t.currentTarget.dataset.cservice + "&store_id=" + this.data.store_id;
        wx.navigateTo({
            url: a,
            fail: function(t) {
                o.tips("客服路由出错");
            }
        });
    },
    goStoreAlbums: function() {
        wx.navigateTo({
            url: "/packageG/independent_store/store_album/store_album?store_id=" + this.data.store_id
        });
    },
    goCouponStore: function() {
        wx.navigateTo({
            url: "/packageD/coupon/coupon_store"
        });
    },
    goO2oStore: function(t) {
        "comment" === t.currentTarget.dataset.type ? wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=".concat(this.data.store_id, "&activeType=comment")
        }) : wx.navigateTo({
            url: "/packageC/o2o/o2oStore/o2oStore?store_id=".concat(this.data.store_id)
        });
    }
});